package com.wss.common.manage;

import ohos.aafwk.ability.Ability;
import java.util.HashSet;
import java.util.Set;

public class AbilityManage {

    /**
     * 保存所有创建的Ability
     */
    private Set<Ability> allAbilities = new HashSet<>();

    /**
     * 添加Ability到管理器
     * @param ability
     */
    public void addAbility(Ability ability) {
        if (ability != null) {
            allAbilities.add(ability);
        }
    }

    /**
     * 从管理器移除Ability
     * @param ability
     */
    public void removeAbility(Ability ability) {
        if (ability != null) {
            allAbilities.remove(ability);
        }
    }

    /**
     * 关闭所有Ability
     */
    public void finishAll() {
        for (Ability ability : allAbilities) {
            ability.terminateAbility();
        }
    }
}
